<template>
  <div>
    <div class="order">
      <div class="order_hander">
        <h1 class="order_title">订单管理</h1>
      </div>
      <div class="order_Search">
        <el-select v-model="value" placeholder="请选择">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
        <el-input class="input" v-model="input" placeholder="关键词"></el-input>
        <el-button @click="orderSerch" class="inquireBtn">查询</el-button>
      </div>
      <div class="order_Content">
        <el-table :data="tableData" stripe border style="width: 100%" @row-click="handle">
          <el-table-column prop="orderNo" label="订单号" width="180"></el-table-column>
          <el-table-column prop="receiverName" label="收件人" width="180"></el-table-column>
          <el-table-column prop="statusDesc" label="订单状态"></el-table-column>
          <el-table-column prop="payment" label="订单总价"></el-table-column>
          <el-table-column prop="createTime" label="创建时间"></el-table-column>
          <el-table-column label="操作" prop="status">
            <template slot-scope="scope">
              <span @click.prevent="myedit(scope.row)">查看</span>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          background
          :total="total"
          :page-size="pagesize"
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>


<script>
import { order, orderId } from "@/request/http";
export default {
  data() {
    return {
      options: [
        {
          value: "orderid",
          label: "按订单号查询"
        }
      ],
      value: "",
      input: "",
      tableData: [],
      pagesize: 9,
      currpage: 1,
      data: {},
      total: 0
    };
  },
  mounted() {
    order(this.currpage).then(res => {
      console.log(res.data.data);
      this.total = res.data.data.total;
      this.tableData = res.data.data.list;
    });
  },
  methods: {
    orderSerch() {
      if (this.value) {
        if (this.value === "orderid") {
          orderId(this.input).then(res => {
            this.tableData = res.data.data.list;
          });
        }
      } else {
        this.$message({
          message: "请选择如何查询条件",
          type: "warning"
        });
      }
    },
    handleCurrentChange(cpage) {
      this.currpage = cpage;
      order(this.currpage).then(res => {
        console.log(res.data.data);
        this.total = res.data.data.total;
        this.tableData = res.data.data.list;
      });
    },
    handleSizeChange(psize) {
      this.pagesize = psize;
    },
    handle(row, event, column) {
      this.data = row;
    },
    myedit(v) {
      if (v.orderNo) {
        this.$router.push({
          path: `./orderdetail`,
          query: {
            data: v.orderNo
          }
        });
      } else {
        return;
      }
    }
  }
};
</script>

<style  scoped>
.order_Content {
  margin-top: 1%;
}
.inquireBtn {
  margin-left: 1%;
}
.input {
  width: 18%;
  margin-left: 1%;
}
.order_Search {
  display: flex;
  justify-content: left;
}
.order_hander {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.order_title {
  display: inline-block;
  font-weight: normal;
}
.order {
  width: 95%;
  margin: 0 auto;
}
</style>